package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.common.exception.DtsException;
import org.common.model.User;
import org.common.model.ro.UserRO;
import org.example.mapper.UserMapper;
import org.example.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void register(UserRO ro) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", ro.getEmail());
        queryWrapper.eq("deleted", 0);
        User existedUser = userMapper.selectOne(queryWrapper);
        if (null != existedUser) {
            throw new DtsException(201,"201","该邮箱已注册！");
        }
        User user = new User();
        BeanUtils.copyProperties(ro, user);
        this.save(user);
    }
}
